package com.myadapter;

import java.util.ArrayList;

import com.bean.TopicMap;
import com.example.lizhiinformation.R;
import com.ownload.Httputil;
import com.ownload.Httputil.OnNetWorkBitmpResponse;
import com.tools.Path_URL;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class TopicMapAdapter extends PagerAdapter {
	private ArrayList<TopicMap> maps;
	private Context context;
	private ArrayList<View> views;
	public TopicMapAdapter(ArrayList<TopicMap> maps, Context context) {
		super();
		this.maps = maps;
		this.context = context;
		views=new ArrayList<View>();
		for (int i = 0; i < maps.size(); i++) {
			View view = LayoutInflater.from(context).inflate(R.layout.map_items, null);
			final ImageView topimage = (ImageView) view.findViewById(R.id.mapimage);
			Httputil.OnworkBitmaDown(Path_URL.IMAGEURL+maps.get(i).getPhoto(), new OnNetWorkBitmpResponse() {
				
				@Override
				public void OK(Bitmap bitmap) {
					// TODO Auto-generated method stub
					topimage.setImageBitmap(bitmap);
				}
				
				@Override
				public void ERROR(String error) {
					// TODO Auto-generated method stub
					
				}
			});
			views.add(view);
		}
	}
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		View view = views.get(position);
		container.addView(view);
		return view;
	}
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		container.removeView(views.get(position));
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return views.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}

}
